<?php
namespace app\logic;

use app\models\Address;
use yii\db\Query;


class AreaLogic
{
    public function getProvince(){
        return Address::find()->where(['region_level'=>1])->asArray()->all();
    }

    public function getCity(){
        return Address::find()->where(['region_level'=>2])->asArray()->all();
    }

    public function getDistrict(){
        return Address::find()->where(['region_level'=>3])->asArray()->all();
    }

    public function getStreet(){
        return Address::find()->where(['region_level'=>4])->asArray()->all();
    }

    public function saveRemark($street_id,$remark){
        $area = Address::findOne(['region_code'=>$street_id]);
        $area->remark = $remark;
        return $area->save();
    }

    public function getSelProvince($province_id){
        return Address::find()->where(['region_level'=>1,'region_code'=>$province_id])->asArray()->one();
    }

    public function getProvinces($province_id){
        return Address::find()->where("region_level=1 AND region_code!='$province_id'")->asArray()->all();
    }

    public function getSelCity($city_id){
        return Address::find()->where(['region_level'=>2,'region_code'=>$city_id])->asArray()->one();
    }
    public function getCitys($province_id,$city_id){
        //return Area::find()->where(['region_level'=>2,'parent_code'=>$province_id,['<>','region_code',$city_id]])->asArray()->all();
        return Address::find()->where("region_level=2 AND parent_code='$province_id' AND region_code!='$city_id'")->asArray()->all();
    }

    public function getSelDistrict($district_id){
        return Address::find()->where(['region_level'=>3,'region_code'=>$district_id])->asArray()->one();
    }
    public function getDistricts($city_id,$district_id){
        //return Area::find()->where(['region_level'=>3,'parent_code'=>$city_id,['<>','region_code',$district_id]])->asArray()->all();
        return Address::find()->where("region_level=3 AND parent_code='$city_id' AND region_code!='$district_id'")->asArray()->all();
    }

    public function getSelStreet($street_id){
        return Address::find()->where(['region_level'=>4,'region_code'=>$street_id])->asArray()->one();
    }
    public function getStreets($district_id,$street_id){
        //return Area::find()->where(['region_level'=>4,'parent_code'=>$district_id,['<>','region_code',$street_id]])->asArray()->all();
        return Address::find()->where("region_level=4 AND parent_code='$district_id' AND region_code!='$street_id'")->asArray()->all();
    }

}